package novel.web.controller;

import novel.spider.entitys.Chapter;
import novel.spider.entitys.ChapterDetail;
import novel.spider.interfaces.IChapterDetailSpider;
import novel.spider.interfaces.IChapterSpider;
import novel.spider.util.ChapterDetailSpiderFactory;
import novel.spider.util.ChapterSpiderrFactory;
import novel.spider.util.NovelSpiderUtil;
import novel.web.entitys.JSONResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by Kau on 2016/11/28.
 */
@Controller
public class NovelController {
    static {
        NovelSpiderUtil.setConfigPath("F:\\Java_Working\\NovelSpider\\src\\conf\\Spider_Rules.xml");
    }

    @RequestMapping(value = "/chapters.do",method = RequestMethod.GET)
    @ResponseBody
    public JSONResponse getChapter(String url){
        IChapterSpider spider = ChapterSpiderrFactory.getChapterSpider(url);
        List<Chapter> chapters = spider.getsChapter(url);
        return JSONResponse.seccess(chapters);
    }

    @RequestMapping(value = "/chapterDetail.do", method = RequestMethod.GET)
    @ResponseBody
    public JSONResponse getChapterDetail(String url){
        IChapterDetailSpider spider = ChapterDetailSpiderFactory.getChapterDetailSpider(url);
        ChapterDetail detail = spider.getChapterDetail(url);
        return JSONResponse.seccess(detail);
    }
}
